import React from "react";
import {connect}from "react-redux";
import {getNewsList} from "../api/news";
import {changeNewsList, initNewsList} from "../store/actions/newsList";

const {Component} = require("react");

class News extends Component {

    componentDidMount() {
    //     getNewsList(1, 10,).then(res => {
    //         debugger
    //         this.props.dispatchChangeNewsList(res.data.rows)
    //     })
    

        this.props.dispatchInitNewsList(1,10)

}

    render() {
        const {newsList} = this.props;
        return (
            <div>
                <ul>
                    {
                        newsList.map(item => (
                            <li key={item.articleId}>{item.title}</li>
                        ))
                    }
                </ul>
            </div>
        )
    }
}

export default connect(state => ({
    newsList: state.newsList.newsList
}), dispatch => ({
    // dispatchChangeNewsList(list) {
    //     dispatch(changeNewsList(list))
    // }
        dispatchInitNewsList(pageNum, pageSize) {
        dispatch(initNewsList(pageNum,pageSize))
        
    }
    

}))(News);
